﻿// ImageLoader.cs
//

using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace MedLink2011.Core {

    public sealed class ImageLoader : IValueConverter {

        public string UriFormat {
            get;
            set;
        }

        #region Implementation of IValueConverter
        object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture) {
            string s = (string)value;
            if (String.IsNullOrEmpty(s)) {
                return null;
            }

            string url = String.Format(UriFormat, value);
            return new BitmapImage(new Uri(Application.Current.Host.Source, url));
        }

        object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
            throw new NotImplementedException();
        }
        #endregion
    }
}
